CROSS_COMPILE = arm-linux-gnueabihf-
VERSION       = 1.0

CC            = ${CROSS_COMPILE}gcc
AR            = ${CROSS_COMPILE}ar
ARFLAGS       = rv

LFLAGS        = -fPIC -shared
CFLAGS        = -g -Wall -Werror -std=gnu99 -fstack-protector-all -fPIC -shared
DEBUGS        = -DNO_DEBUG

INCLUDE       = -I ./include  
LIBS          = -L ./lib 

SOURCES       = $(wildcard ./src/*.c)
OBJS          = $(patsubst %.c, %.o, $(SOURCES))

TARGET        = app
TLIB_A        = lib${TARGET}.a
TLIB_SO       = lib${TARGET}.so

all:${TARGET} ${TLIB_A} ${TLIB_SO}

#execute bin in elf
${TARGET}:$(OBJS)
	@mkdir -p build
	$(CC) $(OBJS) ${LIBS} -o build/$(TARGET)-$(VERSION) 

#static libary
${TLIB_A}:${OBJS}
	@mkdir -p build
	$(AR) ${ARFLAGS} build/$(TLIB_A).$(VERSION) $(OBJS)

#dynamic libary
${TLIB_SO}:${OBJS}
	@mkdir -p build
	$(CC) ${OBJS} ${LIBS} ${LFLAGS} -o build/$(TLIB_SO).$(VERSION)

#compile
%.o:%.c
	$(CC) $(INCLUDE) $(DEBUGS) ${CFLAGS} -c $< -o $@ 
	
.PHONY:clean
clean:
	 @echo "remove app and objs files ..."
	 rm -rf $(OBJS) $(target) build
